package org.example.aienglishapp.service.operationlog;

import org.example.aienglishapp.entity.operationlog.OperationLog;
import org.example.aienglishapp.mapper.operationlog.OperationLogMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class OperationLogService {

    private static final Logger logger = LoggerFactory.getLogger(OperationLogService.class);

    @Autowired
    private OperationLogMapper operationLogMapper;

    public void insertOperationLog(OperationLog log) {
        log.setElapsedTime(100L); // 假设执行时间为100毫秒
        log.setCreateTime(LocalDateTime.now()); // 当前时间
        log.setIpAddress("127.0.0.1"); // 假设IP地址为127.0.0.1
        logger.info("Inserting operation log: {}", log);
        operationLogMapper.insert(log);
    }

    public List<OperationLog> getAllOperationLogs() {
        List<OperationLog> logs = operationLogMapper.selectAll();
        logger.info("Fetched {} operation logs", logs.size());
        return logs;
    }

    public void deleteById(Long id) {
        operationLogMapper.deleteById(id);
    }
}
